<?php   
 /* CAT:Bar Chart */
@header('Content-Type: text/html; charset=utf-8');
 /* pChart library inclusions */
 include("../class/pData.class.php");
 include("../class/pDraw.class.php");
 include("../class/pImage.class.php");

 $result = GetMaxs();
 /* Create and populate the pData object */
 $MyData = new pData();  
 $MyData->setAxisName(0,"关键字搜索次数");
 $MyData->addPoints(array($result[0][1],$result[1][1],$result[2][1],$result[3][1],$result[4][1],$result[5][1],$result[6][1],$result[7][1]),"关键字");
 $MyData->addPoints(array($result[0][0],$result[1][0],$result[2][0],$result[3][0],$result[4][0],$result[5][0],$result[6][0],$result[7][0]),"Months");
 $MyData->setSerieDescription("Months","Month");
 $MyData->setAbscissa("Months");

 /* Create the pChart object */
 $myPicture = new pImage(700,230,$MyData);

 /* Turn of Antialiasing */
 $myPicture->Antialias = FALSE;

 /* Add a border to the picture */
 $myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));

 /* Set the default font */
 $myPicture->setFontProperties(array("FontName"=>"../fonts/MSYH.ttf","FontSize"=>10));

 /* Define the chart area */
 $myPicture->setGraphArea(60,40,650,200);

 /* Draw the scale */
 $scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE);
 $myPicture->drawScale($scaleSettings);

 /* Write the chart legend */
 $myPicture->drawLegend(580,12,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));

 /* Turn on shadow computing */ 
 $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));

 /* Draw the chart */
 $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
 $settings = array("Gradient"=>TRUE,"GradientMode"=>GRADIENT_EFFECT_CAN,"DisplayPos"=>LABEL_POS_INSIDE,"DisplayValues"=>TRUE,"DisplayR"=>255,"DisplayG"=>255,"DisplayB"=>255,"DisplayShadow"=>TRUE,"Surrounding"=>10);
 $myPicture->drawBarChart();

 /* Render the picture (choose the best way) */
 $myPicture->autoOutput("pictures/example.drawBarChart.simple.png");
 
 function GetMaxs(){
	$con = mysql_connect("127.0.0.1","root","redhat");
	if (!$con)
	{
		die('Could not connect: ' . mysql_error());
	}

	mysql_select_db("kfcmenu", $con);
	mysql_query("set names utf8");

	$query_str = "select keyword,search_times from keyinfo order by search_times desc;";
	$db_result = mysql_query($query_str);

	$result = array();
	while($row = mysql_fetch_array($db_result))
	{
		/*$times = $row['search_times'];
		$k = $row['keyword'];
		$result[$k] = $times;*/
		$temp = array($row['keyword'], $row['search_times']);
		array_push($result, $temp);
	}
	
	mysql_close($con);
	return $result;
}
?>

